/*
 * Copyright (c) 2025 Huawei Device, Inc. Ltd. and <马弓手>.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef MYAPPLICATION_FILEUTILS_H
#define MYAPPLICATION_FILEUTILS_H

#include "CordovaPlugin.h"
#include "cJSON.h"
#include "Filesystem.h"

class FileUtils : CordovaPlugin{
    enum error_code {
        NOT_FOUND_ERR = 1,
        SECURITY_ERR = 2,
        ABORT_ERR = 3,
        
        NOT_READABLE_ERR = 4,
        ENCODING_ERR = 5,
        NO_MODIFICATION_ALLOWED_ERR = 6,
        INVALID_STATE_ERR = 7,
        SYNTAX_ERR = 8,
        INVALID_MODIFICATION_ERR = 9,
        QUOTA_EXCEEDED_ERR = 10,
        TYPE_MISMATCH_ERR = 11,
        PATH_EXISTS_ERR = 12,
    };
    
    CallbackContext m_cbc;
    cJSON* requestAllPaths();
    static vector<CFilesystem::Filesystem> m_vecFilesystems;
public:
    struct LocalFilesystemURL {
        string m_strUri;
        string m_strFsName;
        string m_strFileName;
        string m_strPath;
        bool m_isDirectory;
        long m_lngSize;
    };
    FileUtils(){
    }
    ~FileUtils() {
    };
    bool execute(const string&  actionAsString, cJSON* args, CallbackContext cbc) override;
    void pluginInitialize() override;
    static LocalFilesystemURL resolveNativeUri(const string & strFilePath);
    static cJSON* makeEntryForUrl(const string & strFilePath);
    static cJSON* getFileMetadataForLocalURL(const string& strFilePath, const string& strFullPath);
    static string getMimeType(const string& strFilePath);
    bool onArKTsResult(cJSON* args);
};

#endif //MYAPPLICATION_FILEUTILS_H
